#include "common.h"
#include "argument.h"

Argument::Argument(int argc, char *argv[]): mode(commandMode), fileName(0)
{
	switch(argc)
	{
	case 2:
		if (argv[1][0] == '-')
		{
			this->setMode(argv[1][1]);
		}
		else
		{
			this->setFileName(argv[1]);
		}
		break;
	case 3:
		if (argv[1][0] == '-')
		{
			this->setMode(argv[1][1]);
		}
		else
		{
			this->setFileName(argv[1]);
		}
		
		if (argv[2][0] == '-')
		{
			this->setMode(argv[2][1]);
		}
		else
		{
			this->setFileName(argv[2]);
		}
		break;
	}
}

Argument::~Argument()
{
	
}

int Argument::getMode() const
{
	return this->mode;
}

const char *Argument::getFileName() const
{
	
	return this->fileName;
}

void Argument::setFileName(char *f)
{
	this->fileName = new char[strlen(f) + 1];
	strcpy(this->fileName, f);
}

void Argument::setMode(char m)
{
	switch(m)
	{
	case 'i':
		this->mode = insertMode;
		break;
	case 'l':
		this->mode = lineMode;
		break;
	case 'c':
	default:
		this->mode = commandMode;
		break;
	}
}
